package com.zlw.rabbitmq.topic;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author Zhaoluowei
 * @version 1.0
 * @date 2019/12/22 15:04
 */
public class TopicProducter_two {

    public static void main(String[] args) throws IOException, TimeoutException {
        //1.
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setVirtualHost("/");
        connectionFactory.setHost("39.100.250.122");
        connectionFactory.setPort(5672);
        connectionFactory.setUsername("guest");
        connectionFactory.setPassword("guest");

        //2
        Connection connection = connectionFactory.newConnection();

        //3.
        Channel channel = connection.createChannel();
        //4. 声明
        String exchangeName = "test_topic_exchange";
        String routingKey = "test.topic.two";

        //5. 发送
        String msg = "Hello RabbitMQ Topic TopicProducter_two Exchange Message ...";
        channel.basicPublish(exchangeName,routingKey,null,msg.getBytes());

        //6. 关闭
        channel.close();
        connection.close();

    }

}
